<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<html>
<head>
    <%
        String contextPath = request.getContextPath();
        String basePath = request.getScheme() + "://"
                + request.getServerName() + ":" + request.getServerPort()
                + contextPath + "/";
    %>
    <base href="<%=basePath%>">
    <meta charset="utf-8">
    <title>航空公司管理</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link href="assets/admin/css/bootstrap.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="css/admin/style.css"/>
    <link href="assets/admin/css/codemirror.css" rel="stylesheet">
    <link rel="stylesheet" href="assets/admin/css/ace.min.css"/>
    <link rel="stylesheet" href="fonts/admin/css/font-awesome.min.css"/>
    <!--[if lte IE 8]>
    <link rel="stylesheet" href="assets/admin/css/ace-ie.min.css"/>
    <![endif]-->
    <link rel="stylesheet" href="css/admin/layui.css" media="all">
    <script src="js/jquery-1.11.0.min.js"></script>
    <script src="assets/admin/js/typeahead-bs2.min.js"></script>
    <script src="js/admin/lrtk.js" type="text/javascript"></script>
    <script src="assets/admin/js/jquery.dataTables.min.js"></script>
    <script src="assets/admin/js/jquery.dataTables.bootstrap.js"></script>
    <script src="assets/admin/layer/layer.js" type="text/javascript"></script>
    <script src="js/admin/layui.js"></script>
</head>

<body>
<div class="page-content clearfix">
    <div class="sort_style">
        <div class="border clearfix">
       <span class="l_f">
        <a href="javascript:void(0)" id="sort_add" class="btn btn-warning"><i class="fa fa-plus"></i> 新增</a>
        <a href="javascript:void(0)" class="btn btn-danger"><i class="fa fa-trash"></i> 批量删除</a>
       </span>
            <span class="r_f">共：<b>5</b>类</span>
        </div>
        <div class="sort_list">

          <%--  <table class="layui-table" lay-data="{height:315, url:'/airline/findAllAirline/', page:true, id:'test'}" lay-filter="test">
                <thead>
                <tr>
                    <th width="25px"><label><input type="checkbox" class="ace"><span class="lbl"></span></label></th>
                    <th lay-data="{field:'airlineId', width:80, sort: true}">航空公司ID</th>
                    <th lay-data="{field:'airlineName', width:80}">公司名称</th>
                    <th lay-data="{field:'icon', width:80, sort: true}">公司图标</th>
                    <th lay-data="{field:'phone'}">联系电话</th>
                    <th lay-data="{field:'address'}">公司地址</th>
                    <th lay-data="{field:'ontimeRate', sort: true}">准点率</th>
                    <th lay-data="{field:'alipayUID'}">支付包账号</th>
                    <th lay-data="{field:'registerTime', sort: true}">注册时间</th>
                    <th lay-data="{field:'description'}">描述</th>
                </tr>
                </thead>
            </table>--%>


            <table class="table table-striped table-bordered table-hover" id="sample-table">
                <thead>
                <tr>
                    <th width="25px"><label><input type="checkbox" class="ace"><span class="lbl"></span></label></th>
                    <th width="150px">航空公司ID</th>
                    <th width="150px">公司名称</th>
                    <th width="150px">公司图标</th>
                    <th width="150px">联系电话</th>
                    <th width="150px">公司地址</th>
                    <th width="150px">到达准点率</th>
                    <th width="150px">支付包账号</th>
                    <th width="150px">注册时间</th>
                    <th width="150px">描述</th>
                    <th width="150px">操作</th>
                </tr>
                </thead>
                <tbody id="simple-table-body">
<%--                <c:forEach items="${airlines}" var="airline">
                    <tr>
                    <td><label><input type="checkbox" class="ace"><span class="lbl"></span></label></td>
                    <td>${airline.airlineId}</td>
                    <td>${airline.airlineName}</td>
                    <td>${airline.icon}</td>
                    <td>${airline.phone}</td>
                    <td>${airline.address}</td>
                    <td>${airline.ontimeRate}</td>
                    <td>${airline.alipayUID}</td>
                    <td>${airline.registerTime}</td>
                    <td>${airline.description}</td>
                    <td class="td-manage">
                        <a onClick="member_stop(this,'10001')" href="javascript:;" title="停用"
                           class="btn btn-xs btn-success"><i class="fa fa-check  bigger-120"></i></a>
                        <a title="编辑" onclick="member_edit('编辑','member-add.html','4','','510')" href="javascript:;"
                           class="btn btn-xs btn-info"><i class="fa fa-edit bigger-120"></i></a>
                        <a title="删除" href="javascript:;" onclick="member_del(this,'1')" class="btn btn-xs btn-warning">
                            <i class="fa fa-trash  bigger-120"></i></a>
                        <a href="javascript:void(0)" name="Ads_list.html" class="btn btn-xs btn-pink ads_link"
                           onclick="AdlistOrders('561');" title="幻灯片广告列表"><i class="fa  fa-bars  bigger-120"></i></a>
                    </td>
                </tr>
                </c:forEach>--%>
                <%--<tr>
                    <td><label><input type="checkbox" class="ace"><span class="lbl"></span></label></td>
                    <td>1223</td>
                    <td>南方航空</td>
                    <td>img/22</td>
                    <td>12121223</td>
                    <td>深圳宝山区</td>
                    <td>8.0</td>
                    <td>34323423434</td>
                    <td>2016-6-29 12:34</td>
                    <td>南方航空描述...</td>
                    <td class="td-manage">
                        <a onClick="member_stop(this,'10001')" href="javascript:;" title="停用"
                           class="btn btn-xs btn-success"><i class="fa fa-check  bigger-120"></i></a>
                        <a title="编辑" onclick="member_edit('编辑','member-add.html','4','','510')" href="javascript:;"
                           class="btn btn-xs btn-info"><i class="fa fa-edit bigger-120"></i></a>
                        <a title="删除" href="javascript:;" onclick="member_del(this,'1')" class="btn btn-xs btn-warning">
                            <i class="fa fa-trash  bigger-120"></i></a>
                        <a href="javascript:void(0)" name="Ads_list.html" class="btn btn-xs btn-pink ads_link"
                           onclick="AdlistOrders('561');" title="幻灯片广告列表"><i class="fa  fa-bars  bigger-120"></i></a>
                    </td>
                </tr>--%>
                </tbody>
            </table>
        </div>
    </div>
</div>
<!--添加分类-->
<form class="sort_style_add margin" id="sort_style_add" style="display:none" method="post">
    <div class="">
        <ul>
  <%--          <li><label class="label_name"></label>
                <div class="col-sm-9"><input hidden name="airlineId" type="text" placeholder=""
                                             class="col-xs-10 col-sm-5" value="${airline.airlineId}"></div>
            </li>--%>
            <li><label class="label_name">公司名称</label>
                <div class="col-sm-9"><input name="airlineName" type="text" placeholder=""
                                             class="col-xs-10 col-sm-5" value="${airline.airlineName}"></div>
            </li>
            <li><label class="label_name">公司图标</label>
                <div class="col-sm-9"><input name="icon" type="text"  placeholder=""
                                             class="col-xs-10 col-sm-5" value="${airline.icon}"></div>
            </li>
            <li><label class="label_name">联系电话</label>
                <div class="col-sm-9"><input name="phone" type="text"  placeholder=""
                                             class="col-xs-10 col-sm-5" value="${airline.phone}"></div>
            </li>
            <li><label class="label_name">公司地址</label>
                <div class="col-sm-9"><input name="address" type="text"  placeholder=""
                                             class="col-xs-10 col-sm-5" value="${airline.address}"></div>
            </li>
            <li><label class="label_name">准点率</label>
                <div class="col-sm-9"><input name="ontimeRate" type="text"  placeholder=""
                                             class="col-xs-10 col-sm-5" value="${airline.ontimeRate}"></div>
            </li>
            <li><label class="label_name">支付宝账号</label>
                <div class="col-sm-9"><input name="alipayUID" type="text"  placeholder=""
                                             class="col-xs-10 col-sm-5" value="${airline.alipayUID}"></div>
            </li>
            <li><label class="label_name">注册时间</label>
                <div class="col-sm-9"><input name="registerTime" type="text"  placeholder=""
                                             class="col-xs-10 col-sm-5" value="${airline.registerTime}"></div>
            </li>
            <li><label class="label_name">描述</label>
                <div class="col-sm-9"><textarea name="description" class="form-control" id="form-field-8" placeholder=""
                                                onkeyup="checkLength(this);">${airline.description}</textarea><span class="wordage">剩余字数：<span
                        id="sy" style="color:Red;">200</span>字</span></div>
            </li>

        </ul>
    </div>
</form>
</body>
</html>
<script type="text/javascript">
    alert("11");
    $(function () {
        $.post("${pageContext.request.contextPath}/airline/findAll",{},function (airlines) {
            alert("222");
            var str="";
            for (var i=0; i < airlines.length; i++ ){
                var airline=airlines[i];
                str+="<tr>\n" +
                    "                        <td><label><input type=\"checkbox\" class=\"ace\"><span class=\"lbl\"></span></label></td>\n" +
                    "                        <td>"+airline.airlineId+"</td>\n" +
                    "                        <td>"+airline.airlineName+"</td>\n" +
                    "                        <td>"+airline.icon+"</td>\n" +
                    "                        <td>"+airline.phone+"</td>\n" +
                    "                        <td>"+airline.address+"</td>\n" +
                    "                        <td>"+airline.ontimeRate+"</td>\n" +
                    "                        <td>"+airline.alipayUID+"</td>\n" +
                    "                        <td>"+airline.registerTime+"</td>\n" +
                    "                        <td>"+airline.description+"</td>\n" +
                    "                        <td class=\"td-manage\">\n" +
                    "                            <a onClick=\"member_stop(this,'10001')\" href=\"javascript:;\" title=\"停用\"\n" +
                    "                               class=\"btn btn-xs btn-success\"><i class=\"fa fa-check  bigger-120\"></i></a>\n" +
                    "                            <a title=\"编辑\" onclick=\"member_edit('编辑','member-add.html','4','','510')\" href=\"javascript:;\"\n" +
                    "                               class=\"btn btn-xs btn-info\"><i class=\"fa fa-edit bigger-120\"></i></a>\n" +
                    "                            <a title=\"删除\" href=\"javascript:;\" onclick=\"member_del(this,'1')\" class=\"btn btn-xs btn-warning\">\n" +
                    "                                <i class=\"fa fa-trash  bigger-120\"></i></a>\n" +
                    "                            <a href=\"javascript:void(0)\" name=\"Ads_list.html\" class=\"btn btn-xs btn-pink ads_link\"\n" +
                    "                               onclick=\"AdlistOrders('561');\" title=\"幻灯片广告列表\"><i class=\"fa  fa-bars  bigger-120\"></i></a>\n" +
                    "                        </td>\n" +
                    "                    </tr>" ;
            }
            $("#simple-table-body").html(str);
        });
    });


    $('#sort_add').on('click', function () {
        layer.open({
            type: 1,
            title: '新增航空公司信息',
            maxmin: true,
            shadeClose: false, //点击遮罩关闭层
            area: ['750px', ''],
            content: $('#sort_style_add'),
            btn: ['提交', '取消'],
            yes: function (index, layero) {
                var num = 0;
                var str = "";
                $(".sort_style_add input[type$='text']").each(function (n) {
                    if ($(this).val() == "") {
                        layer.alert(str += "" + $(this).attr("name") + "不能为空！\r\n", {
                            title: '提示框',
                            icon: 0,
                        },"json");
                        num++;
                        return false;
                    }
                });
                if (num > 0) {
                    return false;
                } else {
                    $.post("airline/addAirline",$("#sort_style_add").serialize(),function (flag) {
                       if(flag){
                           layer.alert('添加成功！', {
                               title: '提示框',
                               icon: 1,
                           });
                       } else{
                           layer.alert('添加失败！', {
                               title: '提示框',
                               icon: 0,
                           });
                       }
                    });
                   /* layer.alert('添加成功！', {
                        title: '提示框',
                        icon: 1,
                    });*/
                    layer.close(index);
                }
            }
        });
    })


    function checkLength(which) {
        var maxChars = 200; //
        if (which.value.length > maxChars) {
            layer.open({
                icon: 2,
                title: '提示框',
                content: '您出入的字数超多限制!',
            });
            // 超过限制的字数了就将 文本框中的内容按规定的字数 截取
            which.value = which.value.substring(0, maxChars);
            return false;
        } else {
            var curr = maxChars - which.value.length; //250 减去 当前输入的
            document.getElementById("sy").innerHTML = curr.toString();
            return true;
        }
    };

    /*广告图片-停用*/
    function member_stop(obj, id) {
        layer.confirm('确认要关闭吗？', {icon: 0,}, function (index) {
            $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" class="btn btn-xs " onClick="member_start(this,id)" href="javascript:;" title="显示"><i class="fa fa-close bigger-120"></i></a>');
            $(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已关闭</span>');
            $(obj).remove();
            layer.msg('关闭!', {icon: 5, time: 1000});
        });
    }

    /*广告图片-启用*/
    function member_start(obj, id) {
        layer.confirm('确认要显示吗？', {icon: 0,}, function (index) {
            $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" class="btn btn-xs btn-success" onClick="member_stop(this,id)" href="javascript:;" title="关闭"><i class="fa fa-check  bigger-120"></i></a>');
            $(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">显示</span>');
            $(obj).remove();
            layer.msg('显示!', {icon: 6, time: 1000});
        });
    }

    /*广告图片-删除*/
    function member_del(obj, id) {
        layer.confirm('确认要删除吗？', {icon: 0,}, function (index) {
            $(obj).parents("tr").remove();
            layer.msg('已删除!', {icon: 1, time: 1000});
        });
    }

    //面包屑返回值
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.iframeAuto(index);
    $('.Order_form ,.ads_link').on('click', function () {
        var cname = $(this).attr("title");
        var cnames = parent.$('.Current_page').html();
        var herf = parent.$("#iframe").attr("src");
        parent.$('#parentIframe span').html(cname);
        parent.$('#parentIframe').css("display", "inline-block");
        parent.$('.Current_page').attr("name", herf).css({"color": "#4c8fbd", "cursor": "pointer"});
        //parent.$('.Current_page').html("<a href='javascript:void(0)' name="+herf+">" + cnames + "</a>");
        parent.layer.close(index);

    });

    function AdlistOrders(id) {
        window.location.href = "Ads_list.html?=" + id;
    };
</script>
<script type="text/javascript">
    jQuery(function ($) {
        var oTable1 = $('#sample-table').dataTable({
            "aaSorting": [[1, "desc"]],//默认第几个排序
            "bStateSave": true,//状态保存
            "aoColumnDefs": [
                //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
                {"orderable": false, "aTargets": [0, 2, 4, 6, 7,]}// 制定列不参与排序
            ]
        });
        $('table th input:checkbox').on('click', function () {
            var that = this;
            $(this).closest('table').find('tr > td:first-child input:checkbox')
                .each(function () {
                    this.checked = that.checked;
                    $(this).closest('tr').toggleClass('selected');
                });

        });
        $('[data-rel="tooltip"]').tooltip({placement: tooltip_placement});

        function tooltip_placement(context, source) {
            var $source = $(source);
            var $parent = $source.closest('table')
            var off1 = $parent.offset();
            var w1 = $parent.width();

            var off2 = $source.offset();
            var w2 = $source.width();

            if (parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2)) return 'right';
            return 'left';
        }
    })
</script>